package com.changjie.wang.index;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.GetIndexRequest;
import org.elasticsearch.client.indices.GetIndexResponse;


import java.io.IOException;

public class EsClient_SearchIndex {
    public static void main(String[] args) {
        //创建ES客户端
        RestHighLevelClient esClient = new RestHighLevelClient(
                RestClient.builder(new HttpHost("localhost",9200,"http"))
        );
        try {
            //查询索引
            GetIndexRequest request = new GetIndexRequest("user");
            GetIndexResponse response =
                    esClient.indices().get(request,RequestOptions.DEFAULT);
            //响应结果
            System.out.println(response.getAliases());
            System.out.println(response.getMappings());
            System.out.println(response.getSettings());
            System.out.println(response.getDataStreams());
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            //关闭ES客户端
            try {
                esClient.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}
